Combining Sides of Triangle with Contour Lines¶

In this notebook we are going to generate the training data, by which I mean the black and white plots containing, just the contourlines, the ticks of the axes, and axes labels. We implement the code for the plots by reusing and combining code from the previous experiments.

Base plot¶

In [ ]:
import plotly.graph_objects as go

sides = go.Scatterternary(
    a=[1, 0, 0, 1],
    b=[0, 1, 0, 0],
    c=[0, 0, 1, 0],
    mode="lines",
    line_color="black",  # This is a keyword argument
    line_width=2,
    fill="toself",
    fillcolor="rgba(0,0,0,0)",
    # line_shape="spline", # DO not add this line
    # fillcolor="black",
)
fig1 = go.Figure(
    data=[sides],
)
fig1.show()

Remove axis labels, color, etc¶

In [ ]:
layout_dict1 = dict(
    ternary=dict(
        aaxis=dict(
            showgrid=False,
            min=0,
        ),
        baxis=dict(
            showgrid=False,
            min=0,
        ),
        caxis=dict(
            showgrid=False,
            min=0,
        ),
        bgcolor="rgba(0,0,0,0)",
    ),
    paper_bgcolor="rgba(0,0,0,0)",
)

fig1.update_layout(layout_dict1)
In [ ]:
from plotly.figure_factory._ternary_contour import create_ternary_contour
import numpy as np

Al = np.array([0.0, 0.0, 0.0, 0.0, 1.0 / 3, 1.0 / 3, 1.0 / 3, 2.0 / 3, 2.0 / 3, 1.0])
Cu = np.array([0.0, 1.0 / 3, 2.0 / 3, 1.0, 0.0, 1.0 / 3, 2.0 / 3, 0.0, 1.0 / 3, 0.0])
Y = 1 - Al - Cu
# synthetic data for mixing enthalpy
# See https://pycalphad.org/docs/latest/examples/TernaryExamples.html
enthalpy = (Al - 0.01) * Cu * (Al - 0.52) * (Cu - 0.48) * (Y - 1) ** 2
fig: go.Figure = create_ternary_contour(
    np.array([Al, Y, Cu]),
    enthalpy,
    pole_labels=["Al", "Y", "Cu"],
    interp_mode="cartesian",
    coloring="lines",
    linecolor="black",
)
In [ ]:
# fig.add_trace(sides)
# fig.data = fig.data[::-1]
fig.update_layout(layout_dict1)
fig.show()
In [ ]:
fig.layout
Out[ ]:
Layout({
    'height': 500,
    'paper_bgcolor': 'rgba(0,0,0,0)',
    'showlegend': False,
    'template': '...',
    'ternary': {'aaxis': {'linewidth': 2, 'min': 0, 'showgrid': False, 'ticks': 'outside', 'title': {'text': 'Al'}},
                'baxis': {'linewidth': 2, 'min': 0, 'showgrid': False, 'ticks': 'outside', 'title': {'text': 'Y'}},
                'bgcolor': 'rgba(0,0,0,0)',
                'caxis': {'linewidth': 2, 'min': 0, 'showgrid': False, 'ticks': 'outside', 'title': {'text': 'Cu'}},
                'sum': 1},
    'width': 500
})
In [ ]:
import plotly.graph_objects as go

sides = go.Scatterternary(
    a=[1, 0, 0, 1],
    b=[0, 1, 0, 0],
    c=[0, 0, 1, 0],
    mode="lines",
    line_color="black",  # This is a keyword argument
)

fig = go.Figure(
    data=[sides],
    layout={
        "ternary": {
            "aaxis": {"showgrid": False},
            "baxis": {"showgrid": False},
            "caxis": {"showgrid": False},
        }
    },
)
fig.show()
In [ ]:
fig.layout
Out[ ]:
Layout({
    'template': '...',
    'ternary': {'aaxis': {'showgrid': False}, 'baxis': {'showgrid': False}, 'caxis': {'showgrid': False}}
})
In [ ]:
layout_test = dict(
    ternary=dict(
        aaxis=dict(
            showgrid=False,
            # linewidth=2,
            # color="rgba(0,0,0,1)",
        ),
        baxis=dict(
            showgrid=False,
            # linewidth=2,
            # color="rgba(0,0,0,1)",
        ),
        caxis=dict(
            showgrid=False,
            # linewidth=2,
            # color="rgba(0,0,0,1)",
        ),
        bgcolor="rgba(0,0,0,0)",
    ),
    paper_bgcolor="rgba(0,0,0,0)",
)
In [ ]:
import plotly.graph_objects as go

sides = go.Scatterternary(
    a=[1, 0, 0, 1],
    b=[0, 1, 0, 0],
    c=[0, 0, 1, 0],
    mode="lines",
    line_color="black",  # This is a keyword argument
    line_width=2,
)

fig = go.Figure(data=[sides], layout=layout_test)
fig.show()
In [ ]:
fig.data
Out[ ]:
(Scatterternary({
     'a': [1, 0, 0, 1], 'b': [0, 1, 0, 0], 'c': [0, 0, 1, 0], 'line': {'color': 'black', 'width': 2}, 'mode': 'lines'
 }),)

Conclusion¶

Does not work for some reason and I can't figure out why. The "sides" of the triangle don't get drawn even though they should. This avenue of combining the sides with a ternary contour plot may be a dead end. This experiment is a failure, we will try something else in the next experiment.